package com.ruoyi.statisticalCenter.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.InitTableVo;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.common.utils.GetDateStringUtils;
import com.ruoyi.hqfinance.domain.HqNetworkBillDetail;
import com.ruoyi.hqfinance.mapper.HqNetworkBillDetailMapper;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.ScEnterPaiGrossProfitSheetDetail;
import com.ruoyi.logistic.mapper.ScEnterPaiGrossProfitSheetDetailMapper;
import com.ruoyi.statisticalCenter.domain.ScEnterPaiGrossProfitSheet;
import com.ruoyi.statisticalCenter.domain.ScPaiSet;
import com.ruoyi.statisticalCenter.domain.vo.DateStrVo;
import com.ruoyi.statisticalCenter.domain.vo.ScEnterPaiGrossProfitSheetPointVo;
import com.ruoyi.statisticalCenter.domain.vo.ScEnterPaiGrossProfitSheetVo;
import com.ruoyi.statisticalCenter.mapper.ScEnterPaiGrossProfitSheetMapper;
import com.ruoyi.statisticalCenter.mapper.ScPaiSetMapper;
import com.ruoyi.statisticalCenter.service.ScEnterPaiGrossProfitSheetService;
import com.ruoyi.statisticalCenter.utils.BigDecimalUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ScEnterPaiGrossProfitSheetServiceImpl implements ScEnterPaiGrossProfitSheetService {
    @Autowired
    private ScEnterPaiGrossProfitSheetMapper scEnterPaiGrossProfitSheetMapper;
    @Autowired
    private TableService tableService;
    @Autowired
    private HqNetworkBillDetailMapper hqNetworkBillDetailMapper;
    @Autowired
    private ScPaiSetMapper scPaiSetMapper;
    @Autowired
    private ScEnterPaiGrossProfitSheetDetailMapper detailMapper;
    MathContext mc = new MathContext(3, RoundingMode.HALF_UP); // 设置精度为3位，采用四舍五入模式
    private BigDecimal startPrice = new BigDecimal(0);
    private BigDecimal examinePrice = new BigDecimal(0);

    @Override
    public R collect(ScEnterPaiGrossProfitSheetVo vo) {
        PageHelper.startPage(vo.getPageDate());
        List<ScEnterPaiGrossProfitSheet> collect =detailMapper.selectScEnterPaiGrossProfitSheetMapper(vo);
//        List<ScEnterPaiGrossProfitSheet> collect =null;
        if (collect==null || collect.size()==0){
            PageHelper.startPage(vo.getPageDate());
            collect = collectCache(vo);
        }
        BigDecimal policyPrice = new BigDecimal(0);
        BigDecimal starPlanPayPrice = new BigDecimal(0);
        BigDecimal examinePaiFeePrice = new BigDecimal(0);
        ScEnterPaiGrossProfitSheetVo sheetVo = new ScEnterPaiGrossProfitSheetVo();
        BeanUtils.copyProperties(vo, sheetVo);
        //暂未 完成，根据月份获取开始结束时间
        sheetVo.setStartTime("20240501");
        sheetVo.setEndTime("20240531");
        List<ScEnterPaiGrossProfitSheet> scEnterPaiGrossProfitSheets1 = detailMapper.selectScEnterPaiGrossProfitSheetMapper(sheetVo);
        for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : scEnterPaiGrossProfitSheets1) {
            policyPrice = scEnterPaiGrossProfitSheet.getPolicyReciprocityAmount()
                    .divide(new BigDecimal(scEnterPaiGrossProfitSheet.getPolicyReciprocityNum()),9,BigDecimal.ROUND_HALF_UP);
            starPlanPayPrice = scEnterPaiGrossProfitSheet.getStarPlanPayAmount()
                    .divide(new BigDecimal(scEnterPaiGrossProfitSheet.getStarPlanPayNum()),9,BigDecimal.ROUND_HALF_UP);
            examinePaiFeePrice = scEnterPaiGrossProfitSheet.getExaminePaiFeeAmount()
                    .divide(new BigDecimal(scEnterPaiGrossProfitSheet.getExaminePaiFeeNum()),9,BigDecimal.ROUND_HALF_UP);
        }
        //应付承包区金额-考核派费
        if (vo.getNetworkLevel()==1){
            for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : collect) {
                scEnterPaiGrossProfitSheet.setExaminePaiFeePrice(examinePaiFeePrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setStarPlanPayPrice(starPlanPayPrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setPolicyReciprocityPrice(policyPrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setExaminePaiFeeAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getExaminePaiFeeNum()).multiply(examinePaiFeePrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setStarPlanPayAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getStarPlanPayNum()).multiply(starPlanPayPrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setPolicyReciprocityAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getPolicyReciprocityNum()).multiply(policyPrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setTotalDispatchFee(scEnterPaiGrossProfitSheet.getTotalSubsidyAmount()
                        .add(scEnterPaiGrossProfitSheet.getBasePaiFeeAmount()).add(scEnterPaiGrossProfitSheet.getSpecialPaymentAmount()));
                scEnterPaiGrossProfitSheet.setTotalDispatchAmount(scEnterPaiGrossProfitSheet.getTotalDispatchAmount()
                        .add(scEnterPaiGrossProfitSheet.getAssessmentDispatchFee()));
                if (scEnterPaiGrossProfitSheet.getChildren() != null){
                    for (ScEnterPaiGrossProfitSheet child : scEnterPaiGrossProfitSheet.getChildren()) {
                        child.setExaminePaiFeePrice(examinePaiFeePrice.setScale(3,RoundingMode.HALF_UP));
                        child.setStarPlanPayPrice(starPlanPayPrice.setScale(3,RoundingMode.HALF_UP));
                        child.setPolicyReciprocityPrice(policyPrice.setScale(3,RoundingMode.HALF_UP));
                        child.setExaminePaiFeeAmount(new BigDecimal(child.getExaminePaiFeeNum()).multiply(examinePaiFeePrice).setScale(2,RoundingMode.HALF_UP));
                        child.setStarPlanPayAmount(new BigDecimal(child.getStarPlanPayNum()).multiply(starPlanPayPrice).setScale(2,RoundingMode.HALF_UP));
                        child.setPolicyReciprocityAmount(new BigDecimal(child.getPolicyReciprocityNum()).multiply(policyPrice).setScale(2,RoundingMode.HALF_UP));
                        child.setTotalDispatchFee(child.getTotalSubsidyAmount()
                                .add(child.getBasePaiFeeAmount()).add(child.getSpecialPaymentAmount()));
                        child.setTotalDispatchAmount(child.getTotalDispatchAmount()
                                .add(child.getAssessmentDispatchFee()));
                    }
                }
            }
            for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : collect) {
                scEnterPaiGrossProfitSheet.setAssessmentDispatchFee(scEnterPaiGrossProfitSheet.getExaminePaiFeeAmount());
            }
        }
        if (vo.getNetworkLevel() == 0){
            for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : collect) {
                scEnterPaiGrossProfitSheet.setExaminePaiFeePrice(examinePaiFeePrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setExaminePaiFeeAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getExaminePaiFeeNum()).multiply(examinePaiFeePrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setTotalDispatchFee(scEnterPaiGrossProfitSheet.getTotalSubsidyAmount()
                        .add(scEnterPaiGrossProfitSheet.getBasePaiFeeAmount()).add(scEnterPaiGrossProfitSheet.getSpecialPaymentAmount()));
                scEnterPaiGrossProfitSheet.setTotalDispatchAmount(scEnterPaiGrossProfitSheet.getTotalDispatchAmount()
                        .add(scEnterPaiGrossProfitSheet.getAssessmentDispatchFee()));
                scEnterPaiGrossProfitSheet.setStarPlanPayPrice(starPlanPayPrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setPolicyReciprocityPrice(policyPrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setStarPlanPayAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getStarPlanPayNum()).multiply(starPlanPayPrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setPolicyReciprocityAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getPolicyReciprocityNum()).multiply(policyPrice).setScale(2,RoundingMode.HALF_UP));
                if (scEnterPaiGrossProfitSheet.getChildren() != null){
                    for (ScEnterPaiGrossProfitSheet child : scEnterPaiGrossProfitSheet.getChildren()) {
                        child.setExaminePaiFeePrice(examinePaiFeePrice.setScale(3,RoundingMode.HALF_UP));
                        child.setTotalDispatchFee(child.getTotalSubsidyAmount()
                                .add(child.getBasePaiFeeAmount()).add(child.getSpecialPaymentAmount()));
                        child.setTotalDispatchAmount(child.getTotalDispatchAmount()
                                .add(child.getAssessmentDispatchFee()));
                        child.setStarPlanPayPrice(starPlanPayPrice.setScale(3,RoundingMode.HALF_UP));
                        child.setPolicyReciprocityPrice(policyPrice.setScale(3,RoundingMode.HALF_UP));
                        child.setExaminePaiFeeAmount(new BigDecimal(child.getExaminePaiFeeNum()).multiply(examinePaiFeePrice).setScale(2,RoundingMode.HALF_UP));
                        child.setStarPlanPayAmount(new BigDecimal(child.getStarPlanPayNum()).multiply(starPlanPayPrice).setScale(2,RoundingMode.HALF_UP));
                        child.setPolicyReciprocityAmount(new BigDecimal(child.getPolicyReciprocityNum()).multiply(policyPrice).setScale(2,RoundingMode.HALF_UP));
                    }
                }
            }

        }

        collect.stream().forEach(a->{
            a.setCollectDate(vo.getStartTime() + "至" + vo.getEndTime());
        });
        
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("list", PageInfo.info(collect));
        jsonObject.put("fields", getTableVo(vo));
        if (collect == null || collect.size() == 0) {
            return R.ok("暂无数据");
        } else {
            return R.ok(jsonObject);
        }
    }


    public List<ScEnterPaiGrossProfitSheet> collectCache(ScEnterPaiGrossProfitSheetVo vo) {
        List<ScEnterPaiGrossProfitSheet> collect = scEnterPaiGrossProfitSheetMapper.collect(vo);
        BigDecimal marineProjectPerParcelDeduction = scEnterPaiGrossProfitSheetMapper.marineProjectPerParcelDeduction(vo);
        //给网点设置：航海通票扣款、政策互惠扣款、星计划扣款
        //网点的该数据字段为承包区的数据项和
        if (vo.getNetworkLevel()==0){
            ScEnterPaiGrossProfitSheetVo vo1 = new ScEnterPaiGrossProfitSheetVo();
            BeanUtils.copyProperties(vo,vo1);
            vo1.setNetworkLevel(1);
            PageDate page = new PageDate();
            page.setPageSize(10000);
            page.setPageNum(1);
            vo1.setPageDate(page);
            List<ScEnterPaiGrossProfitSheet> scEnterPaiGrossProfitSheets = this.collectCache(vo1);
            BigDecimal marineGeneralPassTicketDeduction = new BigDecimal(0.00);
            BigDecimal policyMutualBenefitDeduction = new BigDecimal(0.00);
            BigDecimal starPlanDeduction = new BigDecimal(0.00);
            for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : scEnterPaiGrossProfitSheets) {
                marineGeneralPassTicketDeduction = marineGeneralPassTicketDeduction.add(scEnterPaiGrossProfitSheet.getMarineGeneralPassTicketDeduction());
                policyMutualBenefitDeduction = policyMutualBenefitDeduction.add(scEnterPaiGrossProfitSheet.getPolicyMutualBenefitDeduction());
                starPlanDeduction = starPlanDeduction.add(scEnterPaiGrossProfitSheet.getStarPlanDeduction());
            }
            for (ScEnterPaiGrossProfitSheet sheet : collect) {
                sheet.setMarineGeneralPassTicketDeduction(marineGeneralPassTicketDeduction);
                sheet.setPolicyMutualBenefitDeduction(policyMutualBenefitDeduction);
                sheet.setStarPlanDeduction(starPlanDeduction);
            }
        }
        for (ScEnterPaiGrossProfitSheet sheet : collect) {
            sheet.setCollectDate(vo.getStartTime() + "至" + vo.getEndTime());
            if (vo.getNetworkLevel() == 0) {
                //设置考核派费、星计划收费-票数与单价
                BigDecimal total = BigDecimal.valueOf(sheet.getTotalDeliveryCount());
                sheet.setExaminePaiFeeNum(total.intValue());
                examinePrice = sheet.getExaminePaiFeeAmount().divide(total,3,BigDecimal.ROUND_HALF_UP);
                //星计划
                sheet.setStarPlanPayNum(total.intValue());
                startPrice = sheet.getStarPlanPayAmount().divide(total,3,BigDecimal.ROUND_HALF_UP);
                sheet.setExaminePaiFeePrice(sheet.getExaminePaiFeeAmount().divide(total,3,BigDecimal.ROUND_HALF_UP));
                sheet.setStarPlanPayPrice(sheet.getStarPlanPayAmount().divide(total,3,BigDecimal.ROUND_HALF_UP));
                /*List<BigDecimal> bigDecimalList = scEnterPaiGrossProfitSheetMapper.marineGeneralPassTotal(vo);
                BigDecimal marineGeneralPassTicketDeduction = sumBigDecimalList(bigDecimalList);
                sheet.setMarineGeneralPassTicketDeduction(marineGeneralPassTicketDeduction);*/
                BigDecimal marineGeneralPassTicketDeduction = sheet.getMarineGeneralPassTicketDeduction();
                BigDecimal totalPaiCount = BigDecimal.valueOf(sheet.getTotalPaiCount());
                if (marineGeneralPassTicketDeduction.compareTo(BigDecimal.ZERO) != 0 && totalPaiCount.compareTo(BigDecimal.ZERO) != 0) {
                    sheet.setMarineSingleParcelDeduction(marineGeneralPassTicketDeduction.divide(totalPaiCount, mc));
                }else {
                    sheet.setMarineSingleParcelDeduction(BigDecimal.valueOf(0));
                }

                /*List<BigDecimal> bigDecimalList1 = scEnterPaiGrossProfitSheetMapper.policyMutualTotal(vo);
                BigDecimal policyMutualBenefitDeduction = sumBigDecimalList(bigDecimalList1);
                sheet.setPolicyMutualBenefitDeduction(policyMutualBenefitDeduction);*/
                BigDecimal policyMutualBenefitDeduction = sheet.getPolicyMutualBenefitDeduction();
                if (policyMutualBenefitDeduction.compareTo(BigDecimal.ZERO) != 0 && totalPaiCount.compareTo(BigDecimal.ZERO) != 0) {
                    sheet.setPolicyMutualBenefitPerParcelDeduction(policyMutualBenefitDeduction.divide(totalPaiCount, mc));
                }else {
                    sheet.setPolicyMutualBenefitPerParcelDeduction(BigDecimal.valueOf(0));
                }
                /*List<BigDecimal> bigDecimalList2 = scEnterPaiGrossProfitSheetMapper.starPlanTotal(vo);
                BigDecimal starPlanDeduction = sumBigDecimalList(bigDecimalList2);
                sheet.setStarPlanDeduction(starPlanDeduction);*/
                BigDecimal starPlanDeduction = sheet.getStarPlanDeduction();
                if (starPlanDeduction.compareTo(BigDecimal.ZERO) != 0 && totalPaiCount.compareTo(BigDecimal.ZERO) != 0) {
                    sheet.setStarPlanPerParcelDeduction(starPlanDeduction.divide(totalPaiCount, mc));
                }else {
                    sheet.setStarPlanPerParcelDeduction(BigDecimal.valueOf(0));
                }
                sheet.setActualPaidDispatchFee(sheet.getTotalDispatchAmount().add(marineGeneralPassTicketDeduction).add(policyMutualBenefitDeduction).add(starPlanDeduction));
                sheet.setSinglePointDispatchFeeAdjustment(scPaiSetMapper.totalAdjustAmount());
                BigDecimal totalTicket = BigDecimal.valueOf(sheet.getTotalPaiCount());
                if (sheet.getActualPaidDispatchFee().add(sheet.getSinglePointDispatchFeeAdjustment()).compareTo(BigDecimal.ZERO) != 0 && totalTicket.compareTo(BigDecimal.ZERO) != 0) {
                    sheet.setActualNetDispatchFee((sheet.getActualPaidDispatchFee().add(sheet.getSinglePointDispatchFeeAdjustment()).divide(totalTicket, mc)));
                }else {
                    sheet.setActualNetDispatchFee(BigDecimal.valueOf(0));
                }
                if (sheet.getNetPerParcelIncome() != null && sheet.getActualNetDispatchFee()!=null) {
                    sheet.setRemainingDispatchFeePerParcel(sheet.getNetPerParcelIncome().subtract(sheet.getActualNetDispatchFee()));
                }else {
                    sheet.setRemainingDispatchFeePerParcel(BigDecimal.valueOf(0));
                }
                //sheet.setMarineGeneralPassTicketDeduction(sheet.getMarineSingleParcelDeduction().multiply(BigDecimal.valueOf(sheet.getTotalPaiCount())));
                //sheet.setPolicyMutualBenefitDeduction(sheet.getPolicyMutualBenefitPerParcelDeduction().multiply(BigDecimal.valueOf(sheet.getTotalPaiCount())));
                //sheet.setStarPlanDeduction(sheet.getStarPlanPerParcelDeduction().multiply(BigDecimal.valueOf(sheet.getTotalPaiCount())));
                sheet.setActualPaidDispatchFee(
                        sheet.getStarPlanDeduction().add(sheet.getPolicyMutualBenefitDeduction()).add(sheet.getMarineGeneralPassTicketDeduction())
                                .add(sheet.getTotalDispatchAmount())
                );
                
                BigDecimal totalDispatchProfit = sheet.getDeliveryIncome().subtract(sheet.getActualPaidDispatchFee().add(sheet.getSinglePointDispatchFeeAdjustment()));
                sheet.setTotalDispatchProfit(totalDispatchProfit);
                sheet.setDispatchProfitMargin(totalDispatchProfit.divide(sheet.getDeliveryIncome(), mc));
            }
            if (vo.getNetworkLevel() == 1 || vo.getNetworkLevel() == 2) {
                //设置考核派费、星计划收费-票数与单价
                ScPaiSet byName = scPaiSetMapper.findByName(sheet.getName());
                if (byName!= null) {
                    sheet.setMarineSingleParcelDeduction(byName.getVoyageTicketDeduction());
                    sheet.setStarPlanPayPrice(byName.getStarPlanTicketDeduction());
                    sheet.setStarPlanPerParcelDeduction(byName.getStarPlanTicketDeduction());
                    sheet.setPolicyMutualBenefitPerParcelDeduction(byName.getPolicyReciprocityTicketDeduction());
                }
                BigDecimal total = BigDecimal.valueOf(sheet.getTotalDeliveryCount());
                sheet.setMarineProjectPerParcelDeduction(marineProjectPerParcelDeduction.setScale(3,RoundingMode.HALF_UP));
                sheet.setMarineProjectPaymentAmount(marineProjectPerParcelDeduction.multiply(total).setScale(3,RoundingMode.HALF_UP));
                sheet.setDeliveryIncome(sheet.getTotalDispatchFee().add(sheet.getMarineProjectPaymentAmount()));
                //承包区-实际付给承包区派费
                if (sheet.getTotalDispatchAmount() != null && sheet.getMarineGeneralPassTicketDeduction() != null && sheet.getPolicyMutualBenefitDeduction() != null && sheet.getStarPlanDeduction() != null) {
                    sheet.setActualPaidDispatchFee(sheet.getTotalDispatchAmount().add(sheet.getMarineGeneralPassTicketDeduction()).add(sheet.getPolicyMutualBenefitDeduction()).add(sheet.getStarPlanDeduction()));
                }
                BigDecimal totalTicket = BigDecimal.valueOf(sheet.getTotalPaiCount());
                if (totalTicket.compareTo(BigDecimal.ZERO) != 0) {
                    sheet.setActualNetDispatchFee(
                            (sheet.getActualPaidDispatchFee() != null ? sheet.getActualPaidDispatchFee() : BigDecimal.ZERO)
                                    .add(
                                            (sheet.getSinglePointDispatchFeeAdjustment() != null ? sheet.getSinglePointDispatchFeeAdjustment() : BigDecimal.ZERO)
                                    )
                                    .divide(totalTicket, mc)
                    );
                } else {
                    sheet.setActualNetDispatchFee(null);
                }

                sheet.setRemainingDispatchFeePerParcel((sheet.getNetPerParcelIncome() != null ? sheet.getNetPerParcelIncome() : BigDecimal.ZERO).subtract((sheet.getActualNetDispatchFee() != null ? sheet.getActualNetDispatchFee() : BigDecimal.ZERO)));
                sheet.setMarineGeneralPassTicketDeduction(sheet.getMarineSingleParcelDeduction().multiply(BigDecimal.valueOf(sheet.getTotalPaiCount())));
                sheet.setPolicyMutualBenefitDeduction(sheet.getPolicyMutualBenefitPerParcelDeduction().multiply(BigDecimal.valueOf(sheet.getTotalPaiCount())));
                sheet.setStarPlanDeduction(sheet.getStarPlanPerParcelDeduction().multiply(BigDecimal.valueOf(sheet.getTotalPaiCount())));
                sheet.setActualPaidDispatchFee(
                        sheet.getStarPlanDeduction().add(sheet.getPolicyMutualBenefitDeduction()).add(sheet.getMarineGeneralPassTicketDeduction())
                                .add(sheet.getTotalDispatchAmount())
                );
                
                BigDecimal actualPaidDispatchFee = sheet.getActualPaidDispatchFee() != null ? sheet.getActualPaidDispatchFee() : BigDecimal.ZERO;
                BigDecimal singlePointDispatchFeeAdjustment = sheet.getSinglePointDispatchFeeAdjustment() != null ? sheet.getSinglePointDispatchFeeAdjustment() : BigDecimal.ZERO;

                BigDecimal totalDispatchProfit = sheet.getDeliveryIncome().subtract(actualPaidDispatchFee.add(singlePointDispatchFeeAdjustment));

                sheet.setTotalDispatchProfit(totalDispatchProfit);

                // Check if deliveryIncome is zero before performing division
                if (sheet.getDeliveryIncome().compareTo(BigDecimal.ZERO) != 0) {
                    sheet.setDispatchProfitMargin(totalDispatchProfit.divide(sheet.getDeliveryIncome(), mc));
                } else {
                    sheet.setDispatchProfitMargin(null);
                }
                //单票到手派费与派费和扣款对应不上
                if (sheet.getPerParcelDispatchFee()!=null && sheet.getMarineProjectPerParcelDeduction()!=null){
                    sheet.setNetPerParcelIncome(new BigDecimal(sheet.getPerParcelDispatchFee().replace(",","")).add(sheet.getMarineProjectPerParcelDeduction()));
                }
                sheet.setExaminePaiFeeNum(total.intValue());
                sheet.setExaminePaiFeeAmount(examinePrice.multiply(total).setScale(2,RoundingMode.HALF_UP));
                //星计划
                sheet.setStarPlanPayNum(total.intValue());
                sheet.setStarPlanPayAmount(startPrice.multiply(total).setScale(2,RoundingMode.HALF_UP));
                sheet.setExaminePaiFeePrice(examinePrice.setScale(3,RoundingMode.HALF_UP));
            }
        }
        
        return collect;
    }

    public static BigDecimal sumBigDecimalList(List<BigDecimal> numbers) {
        // Step 1: Initialize sum with zero
        BigDecimal sum = BigDecimal.ZERO;

        // Step 2: Iterate over the list and add each element to sum
        for (BigDecimal number : numbers) {
            if (number == null) {
                number = BigDecimal.ZERO;
            }
            sum = sum.add(number);
        }

        // Step 3: Return the final sum
        return sum;
    }

    @Override
    public List<ScEnterPaiGrossProfitSheet> collectExportList(ScEnterPaiGrossProfitSheetVo vo) {
        List<ScEnterPaiGrossProfitSheet> collect =detailMapper.selectScEnterPaiGrossProfitSheetMapper(vo);
        if (collect==null || collect.size()==0) {
            collect = collectCache(vo);
        }
        return collect;
    }

    @Override
    public List<ScEnterPaiGrossProfitSheet> collectExport(ScEnterPaiGrossProfitSheetVo vo, OutputStream outputStream) {
        List<ScEnterPaiGrossProfitSheet> collect = collectExportList(vo);
        BigDecimal policyPrice = new BigDecimal(0);
        BigDecimal starPlanPayPrice = new BigDecimal(0);
        BigDecimal examinePaiFeePrice = new BigDecimal(0);
        ScEnterPaiGrossProfitSheetVo sheetVo = new ScEnterPaiGrossProfitSheetVo();
        BeanUtils.copyProperties(vo, sheetVo);
        //暂未 完成，根据月份获取开始结束时间
        sheetVo.setStartTime("20240501");
        sheetVo.setEndTime("20240531");
        List<ScEnterPaiGrossProfitSheet> scEnterPaiGrossProfitSheets1 = detailMapper.selectScEnterPaiGrossProfitSheetMapper(sheetVo);
        for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : scEnterPaiGrossProfitSheets1) {
            policyPrice = scEnterPaiGrossProfitSheet.getPolicyReciprocityAmount()
                    .divide(new BigDecimal(scEnterPaiGrossProfitSheet.getPolicyReciprocityNum()),9,BigDecimal.ROUND_HALF_UP);
            starPlanPayPrice = scEnterPaiGrossProfitSheet.getStarPlanPayAmount()
                    .divide(new BigDecimal(scEnterPaiGrossProfitSheet.getStarPlanPayNum()),9,BigDecimal.ROUND_HALF_UP);
            examinePaiFeePrice = scEnterPaiGrossProfitSheet.getExaminePaiFeeAmount()
                    .divide(new BigDecimal(scEnterPaiGrossProfitSheet.getExaminePaiFeeNum()),9,BigDecimal.ROUND_HALF_UP);
        }
        //应付承包区金额-考核派费
        if (vo.getNetworkLevel()==1){
            for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : collect) {
                scEnterPaiGrossProfitSheet.setExaminePaiFeePrice(examinePaiFeePrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setStarPlanPayPrice(starPlanPayPrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setPolicyReciprocityPrice(policyPrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setExaminePaiFeeAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getExaminePaiFeeNum()).multiply(examinePaiFeePrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setStarPlanPayAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getStarPlanPayNum()).multiply(starPlanPayPrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setPolicyReciprocityAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getPolicyReciprocityNum()).multiply(policyPrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setTotalDispatchFee(scEnterPaiGrossProfitSheet.getTotalSubsidyAmount()
                        .add(scEnterPaiGrossProfitSheet.getBasePaiFeeAmount()).add(scEnterPaiGrossProfitSheet.getSpecialPaymentAmount()));
                scEnterPaiGrossProfitSheet.setTotalDispatchAmount(scEnterPaiGrossProfitSheet.getTotalDispatchAmount()
                        .add(scEnterPaiGrossProfitSheet.getAssessmentDispatchFee()));
                if (scEnterPaiGrossProfitSheet.getChildren() != null){
                    for (ScEnterPaiGrossProfitSheet child : scEnterPaiGrossProfitSheet.getChildren()) {
                        child.setExaminePaiFeePrice(examinePaiFeePrice.setScale(3,RoundingMode.HALF_UP));
                        child.setStarPlanPayPrice(starPlanPayPrice.setScale(3,RoundingMode.HALF_UP));
                        child.setPolicyReciprocityPrice(policyPrice.setScale(3,RoundingMode.HALF_UP));
                        child.setExaminePaiFeeAmount(new BigDecimal(child.getExaminePaiFeeNum()).multiply(examinePaiFeePrice).setScale(2,RoundingMode.HALF_UP));
                        child.setStarPlanPayAmount(new BigDecimal(child.getStarPlanPayNum()).multiply(starPlanPayPrice).setScale(2,RoundingMode.HALF_UP));
                        child.setPolicyReciprocityAmount(new BigDecimal(child.getPolicyReciprocityNum()).multiply(policyPrice).setScale(2,RoundingMode.HALF_UP));
                        child.setTotalDispatchFee(child.getTotalSubsidyAmount()
                                .add(child.getBasePaiFeeAmount()).add(child.getSpecialPaymentAmount()));
                        child.setTotalDispatchAmount(child.getTotalDispatchAmount()
                                .add(child.getAssessmentDispatchFee()));
                    }
                }
            }
            for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : collect) {
                scEnterPaiGrossProfitSheet.setAssessmentDispatchFee(scEnterPaiGrossProfitSheet.getExaminePaiFeeAmount());
            }
        }
        if (vo.getNetworkLevel() == 0){
            for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : collect) {
                scEnterPaiGrossProfitSheet.setExaminePaiFeePrice(examinePaiFeePrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setExaminePaiFeeAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getExaminePaiFeeNum()).multiply(examinePaiFeePrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setTotalDispatchFee(scEnterPaiGrossProfitSheet.getTotalSubsidyAmount()
                        .add(scEnterPaiGrossProfitSheet.getBasePaiFeeAmount()).add(scEnterPaiGrossProfitSheet.getSpecialPaymentAmount()));
                scEnterPaiGrossProfitSheet.setTotalDispatchAmount(scEnterPaiGrossProfitSheet.getTotalDispatchAmount()
                        .add(scEnterPaiGrossProfitSheet.getAssessmentDispatchFee()));
                scEnterPaiGrossProfitSheet.setStarPlanPayPrice(starPlanPayPrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setPolicyReciprocityPrice(policyPrice.setScale(3,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setStarPlanPayAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getStarPlanPayNum()).multiply(starPlanPayPrice).setScale(2,RoundingMode.HALF_UP));
                scEnterPaiGrossProfitSheet.setPolicyReciprocityAmount(new BigDecimal(scEnterPaiGrossProfitSheet.getPolicyReciprocityNum()).multiply(policyPrice).setScale(2,RoundingMode.HALF_UP));
                if (scEnterPaiGrossProfitSheet.getChildren() != null){
                    for (ScEnterPaiGrossProfitSheet child : scEnterPaiGrossProfitSheet.getChildren()) {
                        child.setExaminePaiFeePrice(examinePaiFeePrice.setScale(3,RoundingMode.HALF_UP));
                        child.setTotalDispatchFee(child.getTotalSubsidyAmount()
                                .add(child.getBasePaiFeeAmount()).add(child.getSpecialPaymentAmount()));
                        child.setTotalDispatchAmount(child.getTotalDispatchAmount()
                                .add(child.getAssessmentDispatchFee()));
                        child.setStarPlanPayPrice(starPlanPayPrice.setScale(3,RoundingMode.HALF_UP));
                        child.setPolicyReciprocityPrice(policyPrice.setScale(3,RoundingMode.HALF_UP));
                        child.setExaminePaiFeeAmount(new BigDecimal(child.getExaminePaiFeeNum()).multiply(examinePaiFeePrice).setScale(2,RoundingMode.HALF_UP));
                        child.setStarPlanPayAmount(new BigDecimal(child.getStarPlanPayNum()).multiply(starPlanPayPrice).setScale(2,RoundingMode.HALF_UP));
                        child.setPolicyReciprocityAmount(new BigDecimal(child.getPolicyReciprocityNum()).multiply(policyPrice).setScale(2,RoundingMode.HALF_UP));
                    }
                }
            }

        }
        Workbook workbook = new XSSFWorkbook(); // 创建一个新的Excel工作簿
        Sheet sheet = workbook.createSheet("Amount Data"); // 创建一个新的工作表
        // 创建边框样式
        CellStyle borderStyle = workbook.createCellStyle();
        BorderStyle thin = BorderStyle.THIN;
        short blackColorIndex = IndexedColors.BLACK.getIndex();
        borderStyle.setBorderTop(thin);
        borderStyle.setBorderBottom(thin);
        borderStyle.setBorderLeft(thin);
        borderStyle.setBorderRight(thin);
        borderStyle.setTopBorderColor(blackColorIndex);
        borderStyle.setBottomBorderColor(blackColorIndex);
        borderStyle.setLeftBorderColor(blackColorIndex);
        borderStyle.setRightBorderColor(blackColorIndex);

        // 创建表头样式
        CellStyle headerStyle = workbook.createCellStyle();
        Font headerFont = workbook.createFont();
        headerFont.setBold(true);
        headerFont.setFontHeightInPoints((short) 14); // 设置字体大小
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(HorizontalAlignment.CENTER); // 设置水平居中
        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 设置垂直居中
        headerStyle.setBorderTop(thin);
        headerStyle.setBorderBottom(thin);
        headerStyle.setBorderLeft(thin);
        headerStyle.setBorderRight(thin);
        headerStyle.setTopBorderColor(blackColorIndex);
        headerStyle.setBottomBorderColor(blackColorIndex);
        headerStyle.setLeftBorderColor(blackColorIndex);
        headerStyle.setRightBorderColor(blackColorIndex);
        Row headerRow = sheet.createRow(0); // 创建表头行
        
        String[] headers = {"统计日期", "名称", "基础派费付费-金额", "基础派费付费-票数", "基础派费付费-单价", "政策互惠-金额", 
                "政策互惠-票数", "政策互惠-单价", "错签-金额", "错签-票数", "错签-单价", "补签-金额", "补签-票数", "补签-单价", 
                "补贴派费-金额", "补贴派费-票数", "补贴派费-单价", "进港操作费-金额", "进港操作费-票数", "进港操作费-单价", 
                "特价业务付费-金额", "特价业务付费-票数", "特价业务付费-单价", "周期性派费付费-金额", "周期性派费付费-票数", 
                "周期性派费付费-单价", "考核派费-金额", "考核派费-票数", "考核派费-单价", "星计划收费-金额", "星计划收费-票数", 
                "星计划收费-单价", "大货派费付费-金额", "大货派费付费-票数", "大货派费付费-单价", "乡镇村业务费用-金额", 
                "乡镇村业务费用-票数", "乡镇村业务费用-单价", "按需派送业务费用-金额", "按需派送业务费用-票数", 
                "按需派送业务费用-单价", "总派件数", "补贴合计", "单票补贴", "合计派费", "单票派费", "航海扣款-金额", 
                "航海扣款-单票扣款", "单票到手派费", "派件收入", "应付承包区金额-总派件数", "应付承包区金额-基础派费", 
                "应付承包区金额-特价派费", "应付承包区金额-补贴派费", "应付承包区金额-考核派费", "应付承包区金额-合计派费", 
                "应付承包区金额-单票派费", "应付承包区金额-航海通票扣款", "应付承包区金额-航海单票扣款", "应付承包区金额-政策互惠扣款", 
                "应付承包区金额-政策互惠单票扣款", "应付承包区金额-星计划扣款", "应付承包区金额-星计划单票扣款", 
                "应付承包区金额-实际付给承包区派费", "应付承包区金额-单点派费调整", "应付承包区金额-实际到手派费", 
                "进港派件毛利相关属性-单票结余派费", "进港派件毛利相关属性-派费毛利率", "进港派件毛利相关属性-派费毛利合计"};
        
        //当选择的日期为整月的日期条件时，才展示星计划收费的单价和票数
        int year = Integer.valueOf(vo.getStartTime().substring(0,4));
        int month = Integer.valueOf(vo.getStartTime().substring(4,6));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        // 获取月份的第一天
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, 1);
        String firstDayOfMonth = sdf.format(calendar.getTime());
        System.out.println("第一天： " + firstDayOfMonth);

        // 获取月份的最后一天
        calendar.set(year, month, 1);
        calendar.add(Calendar.DATE, -1);
        String lastDayOfMonth = sdf.format(calendar.getTime());
        System.out.println("最后一天： " + lastDayOfMonth);
        
        if (!vo.getStartTime().equals(firstDayOfMonth) || !vo.getEndTime().equals(lastDayOfMonth)){
            headers = new String[]{"统计日期", "名称", "基础派费付费-金额", "基础派费付费-票数", "基础派费付费-单价", "政策互惠-金额",
                    "政策互惠-票数", "政策互惠-单价", "错签-金额", "错签-票数", "错签-单价", "补签-金额", "补签-票数", "补签-单价",
                    "补贴派费-金额", "补贴派费-票数", "补贴派费-单价", "进港操作费-金额", "进港操作费-票数", "进港操作费-单价",
                    "特价业务付费-金额", "特价业务付费-票数", "特价业务付费-单价", "周期性派费付费-金额", "周期性派费付费-票数",
                    "周期性派费付费-单价", "考核派费-金额", "考核派费-票数", "考核派费-单价", "星计划收费-金额", 
                    "大货派费付费-金额", "大货派费付费-票数", "大货派费付费-单价", "乡镇村业务费用-金额",
                    "乡镇村业务费用-票数", "乡镇村业务费用-单价", "按需派送业务费用-金额", "按需派送业务费用-票数",
                    "按需派送业务费用-单价", "总派件数", "补贴合计", "单票补贴", "合计派费", "单票派费", "航海扣款-金额",
                    "航海扣款-单票扣款", "单票到手派费", "派件收入", "应付承包区金额-总派件数", "应付承包区金额-基础派费",
                    "应付承包区金额-特价派费", "应付承包区金额-补贴派费", "应付承包区金额-考核派费", "应付承包区金额-合计派费",
                    "应付承包区金额-单票派费", "应付承包区金额-航海通票扣款", "应付承包区金额-航海单票扣款", "应付承包区金额-政策互惠扣款",
                    "应付承包区金额-政策互惠单票扣款", "应付承包区金额-星计划扣款", "应付承包区金额-星计划单票扣款",
                    "应付承包区金额-实际付给承包区派费", "应付承包区金额-单点派费调整", "应付承包区金额-实际到手派费",
                    "进港派件毛利相关属性-单票结余派费", "进港派件毛利相关属性-派费毛利率", "进港派件毛利相关属性-派费毛利合计"};
        }
        for (int i = 0; i < headers.length; i++) {
            Cell cell = headerRow.createCell(i);
            cell.setCellValue(headers[i]);
            cell.setCellStyle(headerStyle);
        }

        int rowNum = 1; // 行索引从1开始（因为已经有表头行）

        for (ScEnterPaiGrossProfitSheet enterPaiGrossProfitSheet : collect) {
            int c = 0;
            Row dataRow = sheet.createRow(rowNum++);
            Cell cell0 = dataRow.createCell(c++);
            cell0.setCellValue(enterPaiGrossProfitSheet.getCollectDate());
            cell0.setCellStyle(borderStyle);

            Cell cell1 = dataRow.createCell(c++);
            cell1.setCellValue(enterPaiGrossProfitSheet.getName());
            cell1.setCellStyle(borderStyle);

            Cell cell2 = dataRow.createCell(c++);
            cell2.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getBasePaiFeeAmount() != null) {
                cell2.setCellValue(enterPaiGrossProfitSheet.getBasePaiFeeAmount().doubleValue());
            }
            Cell cell3 = dataRow.createCell(c++);
            cell3.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getBasePaiFeeNum() != null) {
                cell3.setCellValue(enterPaiGrossProfitSheet.getBasePaiFeeNum());
            } else {
                cell3.setCellValue(0);
            }

            Cell cell4 = dataRow.createCell(c++);
            cell4.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getBasePaiFeePrice() != null) {
                cell4.setCellValue(enterPaiGrossProfitSheet.getBasePaiFeePrice().doubleValue());
            } else {
                cell4.setCellValue(0);
            }

            Cell cell5 = dataRow.createCell(c++);
            cell5.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPolicyReciprocityAmount() != null) {
                cell5.setCellValue(enterPaiGrossProfitSheet.getPolicyReciprocityAmount().doubleValue());
            } else {
                cell5.setCellValue(0);
            }

            Cell cell6 = dataRow.createCell(c++);
            cell6.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPolicyReciprocityNum() != null) {
                cell6.setCellValue(enterPaiGrossProfitSheet.getPolicyReciprocityNum());
            } else {
                cell6.setCellValue(0);
            }

            Cell cell7 = dataRow.createCell(c++);
            cell7.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPolicyReciprocityPrice() != null) {
                cell7.setCellValue(enterPaiGrossProfitSheet.getPolicyReciprocityPrice().doubleValue());
            } else {
                cell7.setCellValue(0);
            }

            Cell cell8 = dataRow.createCell(c++);
            cell8.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getWrongSignAmount() != null) {
                cell8.setCellValue(enterPaiGrossProfitSheet.getWrongSignAmount().doubleValue());
            } else {
                cell8.setCellValue(0);
            }

            Cell cell9 = dataRow.createCell(c++);
            cell9.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getWrongSignNum() != null) {
                cell9.setCellValue(enterPaiGrossProfitSheet.getWrongSignNum());
            } else {
                cell9.setCellValue(0);
            }

            Cell cell10 = dataRow.createCell(c++);
            cell10.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getWrongSignPrice() != null) {
                cell10.setCellValue(enterPaiGrossProfitSheet.getWrongSignPrice().doubleValue());
            } else {
                cell10.setCellValue(0);
            }

            Cell cell11 = dataRow.createCell(c++);
            cell11.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getRepairSignAmount() != null) {
                cell11.setCellValue(enterPaiGrossProfitSheet.getRepairSignAmount().doubleValue());
            } else {
                cell11.setCellValue(0);
            }

            // 补签-票数
            Cell cell12 = dataRow.createCell(c++);
            cell12.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getRepairSignNum() != null) {
                cell12.setCellValue(enterPaiGrossProfitSheet.getRepairSignNum());
            } else {
                cell12.setCellValue(0);
            }

            // 补签-单价
            Cell cell13 = dataRow.createCell(c++);
            cell13.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getRepairSignPrice() != null) {
                cell13.setCellValue(enterPaiGrossProfitSheet.getRepairSignPrice().doubleValue());
            } else {
                cell13.setCellValue(0);
            }

            // 补贴派费-金额
            Cell cell14 = dataRow.createCell(c++);
            cell14.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getSubsidyPaiFeePayAmount() != null) {
                cell14.setCellValue(enterPaiGrossProfitSheet.getSubsidyPaiFeePayAmount().doubleValue());
            } else {
                cell14.setCellValue(0);
            }

            // 补贴派费-票数
            Cell cell15 = dataRow.createCell(c++);
            cell15.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getSubsidyPaiFeePayNum() != null) {
                cell15.setCellValue(enterPaiGrossProfitSheet.getSubsidyPaiFeePayNum());
            } else {
                cell15.setCellValue(0);
            }

            // 补贴派费-单价
            Cell cell16 = dataRow.createCell(c++);
            cell16.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getSubsidyPaiFeePayPrice() != null) {
                cell16.setCellValue(enterPaiGrossProfitSheet.getSubsidyPaiFeePayPrice().doubleValue());
            } else {
                cell16.setCellValue(0);
            }

            // 进港操作费-金额
            Cell cell17 = dataRow.createCell(c++);
            cell17.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getEntryOperateFeeAmount() != null) {
                cell17.setCellValue(enterPaiGrossProfitSheet.getEntryOperateFeeAmount().doubleValue());
            } else {
                cell17.setCellValue(0);
            }

            // 进港操作费-票数
            Cell cell18 = dataRow.createCell(c++);
            cell18.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getEntryOperateFeeNum() != null) {
                cell18.setCellValue(enterPaiGrossProfitSheet.getEntryOperateFeeNum());
            } else {
                cell18.setCellValue(0);
            }

            // 进港操作费-单价
            Cell cell19 = dataRow.createCell(c++);
            cell19.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getEntryOperateFeePrice() != null) {
                cell19.setCellValue(enterPaiGrossProfitSheet.getEntryOperateFeePrice().doubleValue());
            } else {
                cell19.setCellValue(0);
            }

            // 特价业务付费-金额
            Cell cell20 = dataRow.createCell(c++);
            cell20.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getSpecialPaymentAmount() != null) {
                cell20.setCellValue(enterPaiGrossProfitSheet.getSpecialPaymentAmount().doubleValue());
            } else {
                cell20.setCellValue(0);
            }

            // 特价业务付费-票数
            Cell cell21 = dataRow.createCell(c++);
            cell21.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getSpecialPaymentNum() != null) {
                cell21.setCellValue(enterPaiGrossProfitSheet.getSpecialPaymentNum());
            } else {
                cell21.setCellValue(0);
            }

            // 特价业务付费-单价
            Cell cell22 = dataRow.createCell(c++);
            cell22.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getSpecialPaymentPrice() != null) {
                cell22.setCellValue(enterPaiGrossProfitSheet.getSpecialPaymentPrice().doubleValue());
            } else {
                cell22.setCellValue(0);
            }

            // 周期性派费付费-金额
            Cell cell23 = dataRow.createCell(c++);
            cell23.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPeriodicPaymentAmount() != null) {
                cell23.setCellValue(enterPaiGrossProfitSheet.getPeriodicPaymentAmount().doubleValue());
            } else {
                cell23.setCellValue(0);
            }

            // 周期性派费付费-票数
            Cell cell24 = dataRow.createCell(c++);
            cell24.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPeriodicPaymentNum() != null) {
                cell24.setCellValue(enterPaiGrossProfitSheet.getPeriodicPaymentNum());
            } else {
                cell24.setCellValue(0);
            }

            // 周期性派费付费-单价
            Cell cell25 = dataRow.createCell(c++);
            cell25.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPeriodicPaymentPrice() != null) {
                cell25.setCellValue(enterPaiGrossProfitSheet.getPeriodicPaymentPrice().doubleValue());
            } else {
                cell25.setCellValue(0);
            }

            // 考核派费-金额
            Cell cell26 = dataRow.createCell(c++);
            cell26.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getExaminePaiFeeAmount() != null) {
                cell26.setCellValue(enterPaiGrossProfitSheet.getExaminePaiFeeAmount().doubleValue());
            } else {
                cell26.setCellValue(0);
            }

            // 考核派费-票数
            Cell cell27 = dataRow.createCell(c++);
            cell27.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getExaminePaiFeeNum() != null) {
                cell27.setCellValue(enterPaiGrossProfitSheet.getExaminePaiFeeNum());
            } else {
                cell27.setCellValue(0);
            }

            // 考核派费-单价
            Cell cell28 = dataRow.createCell(c++);
            cell28.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getExaminePaiFeePrice() != null) {
                cell28.setCellValue(enterPaiGrossProfitSheet.getExaminePaiFeePrice().doubleValue());
            } else {
                cell28.setCellValue(0);
            }

            // 星计划收费-金额
            Cell cell29 = dataRow.createCell(c++);
            cell29.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getStarPlanPayAmount() != null) {
                cell29.setCellValue(enterPaiGrossProfitSheet.getStarPlanPayAmount().doubleValue());
            } else {
                cell29.setCellValue(0);
            }
            
            //选择的日期为整月时，才显示这两个字段
            if (vo.getStartTime().equals(firstDayOfMonth) || vo.getEndTime().equals(lastDayOfMonth)){
                // 星计划收费-票数
                Cell cell30 = dataRow.createCell(c++);
                cell30.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getStarPlanPayNum() != null) {
                    cell30.setCellValue(enterPaiGrossProfitSheet.getStarPlanPayNum());
                } else {
                    cell30.setCellValue(0);
                }

                Cell cell31 = dataRow.createCell(c++);
                cell31.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getStarPlanPayPrice() != null) {
                    cell31.setCellValue(enterPaiGrossProfitSheet.getStarPlanPayPrice().doubleValue());
                } else {
                    cell31.setCellValue(0);
                }
            }

           /* if (!vo.getStartTime().substring(5).equals("01") || Integer.parseInt(vo.getStartTime().substring(5))<25){
                // 大货派费付费-金额
                Cell cell32 = dataRow.createCell(c++);
                cell32.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getBulkPaiFeePaymentAmount() != null) {
                    cell32.setCellValue(enterPaiGrossProfitSheet.getBulkPaiFeePaymentAmount().doubleValue());
                } else {
                    cell32.setCellValue(0);
                }

// 大货派费付费-票数
                Cell cell33 = dataRow.createCell(c++);
                cell33.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getBulkPaiFeePaymentNum() != null) {
                    cell33.setCellValue(enterPaiGrossProfitSheet.getBulkPaiFeePaymentNum());
                } else {
                    cell33.setCellValue(0);
                }

// 大货派费付费-单价
                Cell cell34 = dataRow.createCell(c++);
                cell34.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getBulkPaiFeePaymentPrice() != null) {
                    cell34.setCellValue(enterPaiGrossProfitSheet.getBulkPaiFeePaymentPrice().doubleValue());
                } else {
                    cell34.setCellValue(0);
                }

// 乡镇村业务费用-金额
                Cell cell35 = dataRow.createCell(c++);
                cell35.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getTownshipSubsidyPaymentAmount() != null) {
                    cell35.setCellValue(enterPaiGrossProfitSheet.getTownshipSubsidyPaymentAmount().doubleValue());
                } else {
                    cell35.setCellValue(0);
                }

// 乡镇村业务费用-票数
                Cell cell36 = dataRow.createCell(c++);
                cell36.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getTownshipSubsidyPaymentNum() != null) {
                    cell36.setCellValue(enterPaiGrossProfitSheet.getTownshipSubsidyPaymentNum());
                } else {
                    cell36.setCellValue(0);
                }

// 乡镇村业务费用-单价
                Cell cell37 = dataRow.createCell(c++);
                cell37.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getTownshipSubsidyPaymentPrice() != null) {
                    cell37.setCellValue(enterPaiGrossProfitSheet.getTownshipSubsidyPaymentPrice().doubleValue());
                } else {
                    cell37.setCellValue(0);
                }

// 按需派送业务费用-金额
                Cell cell38 = dataRow.createCell(c++);
                cell38.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentAmount() != null) {
                    cell38.setCellValue(enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentAmount().doubleValue());
                } else {
                    cell38.setCellValue(0);
                }

// 按需派送业务费用-票数
                Cell cell39 = dataRow.createCell(c++);
                cell39.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentNum() != null) {
                    cell39.setCellValue(enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentNum());
                } else {
                    cell39.setCellValue(0);
                }

// 按需派送业务费用-单价
                Cell cell40 = dataRow.createCell(c++);
                cell40.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentPrice() != null) {
                    cell40.setCellValue(enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentPrice().doubleValue());
                } else {
                    cell40.setCellValue(0);
                }



                // 总派件数
                Cell cell41 = dataRow.createCell(c++);
                cell41.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getTotalDeliveryCount() != null) {
                    cell41.setCellValue(enterPaiGrossProfitSheet.getTotalDeliveryCount());
                } else {
                    cell41.setCellValue(0);
                }

// 补贴合计
                Cell cell42 = dataRow.createCell(c++);
                cell42.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getTotalSubsidyAmount() != null) {
                    cell42.setCellValue(enterPaiGrossProfitSheet.getTotalSubsidyAmount().doubleValue());
                } else {
                    cell42.setCellValue(0);
                }

// 单票补贴
                Cell cell43 = dataRow.createCell(c++);
                cell43.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getPerParcelSubsidy() != null) {
                    cell43.setCellValue(enterPaiGrossProfitSheet.getPerParcelSubsidy());
                } else {
                    cell43.setCellValue(0);
                }

// 合计派费
                Cell cell44 = dataRow.createCell(c++);
                cell44.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getTotalDispatchFee() != null) {
                    cell44.setCellValue(enterPaiGrossProfitSheet.getTotalDispatchFee().doubleValue());
                } else {
                    cell44.setCellValue(0);
                }

// 单票派费
                Cell cell45 = dataRow.createCell(43);
                cell45.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getPerParcelDispatchFee() != null) {
                    cell45.setCellValue(enterPaiGrossProfitSheet.getPerParcelDispatchFee());
                } else {
                    cell45.setCellValue(0);
                }

// 航海扣款-金额
                Cell cell46 = dataRow.createCell(44);
                cell46.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getMarineProjectPaymentAmount() != null) {
                    cell46.setCellValue(enterPaiGrossProfitSheet.getMarineProjectPaymentAmount().doubleValue());
                } else {
                    cell46.setCellValue(0);
                }

// 航海扣款-单票扣款
                Cell cell47 = dataRow.createCell(45);
                cell47.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getMarineProjectPerParcelDeduction() != null) {
                    cell47.setCellValue(enterPaiGrossProfitSheet.getMarineProjectPerParcelDeduction().doubleValue());
                } else {
                    cell47.setCellValue(0);
                }

// 单票到手派费
                Cell cell48 = dataRow.createCell(46);
                cell48.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getNetPerParcelIncome() != null) {
                    cell48.setCellValue(enterPaiGrossProfitSheet.getNetPerParcelIncome().doubleValue());
                } else {
                    cell48.setCellValue(0);
                }

// 派件收入
                Cell cell49 = dataRow.createCell(47);
                cell49.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getDeliveryIncome() != null) {
                    cell49.setCellValue(enterPaiGrossProfitSheet.getDeliveryIncome().doubleValue());
                } else {
                    cell49.setCellValue(0);
                }

// 应付承包区金额部分
// 总派件数
                Cell cell50 = dataRow.createCell(48);
                cell50.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getTotalPaiCount() != null) {
                    cell50.setCellValue(enterPaiGrossProfitSheet.getTotalPaiCount());
                } else {
                    cell50.setCellValue(0);
                }

// 基础派费
                Cell cell51 = dataRow.createCell(49);
                cell51.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getBaseDispatchFee() != null) {
                    cell51.setCellValue(enterPaiGrossProfitSheet.getBaseDispatchFee().doubleValue());
                } else {
                    cell51.setCellValue(0);
                }

// 特价派费
                Cell cell52 = dataRow.createCell(50);
                cell52.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getSpecialDiscountSubsidyFee() != null) {
                    cell52.setCellValue(enterPaiGrossProfitSheet.getSpecialDiscountSubsidyFee().doubleValue());
                } else {
                    cell52.setCellValue(0);
                }

// 补贴派费
                Cell cell53 = dataRow.createCell(51);
                cell53.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getBonusDispatchFee() != null) {
                    cell53.setCellValue(enterPaiGrossProfitSheet.getBonusDispatchFee().doubleValue());
                } else {
                    cell53.setCellValue(0);
                }

// 考核派费
                Cell cell54 = dataRow.createCell(52);
                cell54.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getAssessmentDispatchFee() != null) {
                    cell54.setCellValue(enterPaiGrossProfitSheet.getAssessmentDispatchFee().doubleValue());
                } else {
                    cell54.setCellValue(0);
                }

// 合计派费
                Cell cell55 = dataRow.createCell(53);
                cell55.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getTotalDispatchAmount() != null) {
                    cell55.setCellValue(enterPaiGrossProfitSheet.getTotalDispatchAmount().doubleValue());
                } else {
                    cell55.setCellValue(0);
                }

// 单票派费
                Cell cell56 = dataRow.createCell(54);
                cell56.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getPerParcelDispatchAmount() != null) {
                    cell56.setCellValue(enterPaiGrossProfitSheet.getPerParcelDispatchAmount().doubleValue());
                } else {
                    cell56.setCellValue(0);
                }

// 航海通票扣款
                Cell cell57 = dataRow.createCell(55);
                cell57.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getMarineGeneralPassTicketDeduction() != null) {
                    cell57.setCellValue(enterPaiGrossProfitSheet.getMarineGeneralPassTicketDeduction().doubleValue());
                } else {
                    cell57.setCellValue(0);
                }

// 航海单票扣款
                Cell cell58 = dataRow.createCell(56);
                cell58.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getMarineSingleParcelDeduction() != null) {
                    cell58.setCellValue(enterPaiGrossProfitSheet.getMarineSingleParcelDeduction().doubleValue());
                } else {
                    cell58.setCellValue(0);
                }

// 政策互惠扣款
                Cell cell59 = dataRow.createCell(57);
                cell59.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getPolicyMutualBenefitDeduction() != null) {
                    cell59.setCellValue(enterPaiGrossProfitSheet.getPolicyMutualBenefitDeduction().doubleValue());
                } else {
                    cell59.setCellValue(0);
                }

// 政策互惠单票扣款
                Cell cell60 = dataRow.createCell(58);
                cell60.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getPolicyMutualBenefitPerParcelDeduction() != null) {
                    cell60.setCellValue(enterPaiGrossProfitSheet.getPolicyMutualBenefitPerParcelDeduction().doubleValue());
                } else {
                    cell60.setCellValue(0);
                }

                // 星计划扣款
                Cell cell61 = dataRow.createCell(59);
                cell61.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getStarPlanDeduction() != null) {
                    cell61.setCellValue(enterPaiGrossProfitSheet.getStarPlanDeduction().doubleValue());
                } else {
                    cell61.setCellValue(0);
                }

// 星计划单票扣款
                Cell cell62 = dataRow.createCell(60);
                cell62.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getStarPlanPerParcelDeduction() != null) {
                    cell62.setCellValue(enterPaiGrossProfitSheet.getStarPlanPerParcelDeduction().doubleValue());
                } else {
                    cell62.setCellValue(0);
                }

// 实际付给承包区派费
                Cell cell63 = dataRow.createCell(61);
                cell63.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getActualPaidDispatchFee() != null) {
                    cell63.setCellValue(enterPaiGrossProfitSheet.getActualPaidDispatchFee().doubleValue());
                } else {
                    cell63.setCellValue(0);
                }

// 单点派费调整
                Cell cell64 = dataRow.createCell(62);
                cell64.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getSinglePointDispatchFeeAdjustment() != null) {
                    cell64.setCellValue(enterPaiGrossProfitSheet.getSinglePointDispatchFeeAdjustment().doubleValue());
                } else {
                    cell64.setCellValue(0);
                }

// 实际到手派费
                Cell cell65 = dataRow.createCell(63);
                cell65.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getActualNetDispatchFee() != null) {
                    cell65.setCellValue(enterPaiGrossProfitSheet.getActualNetDispatchFee().doubleValue());
                } else {
                    cell65.setCellValue(0);
                }

// 进港派件毛利相关属性
// 单票结余派费
                Cell cell66 = dataRow.createCell(64);
                cell66.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getRemainingDispatchFeePerParcel() != null) {
                    cell66.setCellValue(enterPaiGrossProfitSheet.getRemainingDispatchFeePerParcel().doubleValue());
                } else {
                    cell66.setCellValue(0);
                }

// 派费毛利率
                Cell cell67 = dataRow.createCell(65);
                cell67.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getDispatchProfitMargin() != null) {
                    cell67.setCellValue(enterPaiGrossProfitSheet.getDispatchProfitMargin().doubleValue());
                } else {
                    cell67.setCellValue(0);
                }

// 派费毛利合计
                Cell cell68 = dataRow.createCell(66);
                cell68.setCellStyle(borderStyle);
                if (enterPaiGrossProfitSheet.getTotalDispatchProfit() != null) {
                    cell68.setCellValue(enterPaiGrossProfitSheet.getTotalDispatchProfit().doubleValue());
                } else {
                    cell68.setCellValue(0);
                }
            }*/
// 大货派费付费-金额
            Cell cell32 = dataRow.createCell(c++);
            cell32.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getBulkPaiFeePaymentAmount() != null) {
                cell32.setCellValue(enterPaiGrossProfitSheet.getBulkPaiFeePaymentAmount().doubleValue());
            } else {
                cell32.setCellValue(0);
            }

// 大货派费付费-票数
            Cell cell33 = dataRow.createCell(c++);
            cell33.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getBulkPaiFeePaymentNum() != null) {
                cell33.setCellValue(enterPaiGrossProfitSheet.getBulkPaiFeePaymentNum());
            } else {
                cell33.setCellValue(0);
            }

// 大货派费付费-单价
            Cell cell34 = dataRow.createCell(c++);
            cell34.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getBulkPaiFeePaymentPrice() != null) {
                cell34.setCellValue(enterPaiGrossProfitSheet.getBulkPaiFeePaymentPrice().doubleValue());
            } else {
                cell34.setCellValue(0);
            }

// 乡镇村业务费用-金额
            Cell cell35 = dataRow.createCell(c++);
            cell35.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getTownshipSubsidyPaymentAmount() != null) {
                cell35.setCellValue(enterPaiGrossProfitSheet.getTownshipSubsidyPaymentAmount().doubleValue());
            } else {
                cell35.setCellValue(0);
            }

// 乡镇村业务费用-票数
            Cell cell36 = dataRow.createCell(c++);
            cell36.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getTownshipSubsidyPaymentNum() != null) {
                cell36.setCellValue(enterPaiGrossProfitSheet.getTownshipSubsidyPaymentNum());
            } else {
                cell36.setCellValue(0);
            }

// 乡镇村业务费用-单价
            Cell cell37 = dataRow.createCell(c++);
            cell37.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getTownshipSubsidyPaymentPrice() != null) {
                cell37.setCellValue(enterPaiGrossProfitSheet.getTownshipSubsidyPaymentPrice().doubleValue());
            } else {
                cell37.setCellValue(0);
            }

// 按需派送业务费用-金额
            Cell cell38 = dataRow.createCell(c++);
            cell38.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentAmount() != null) {
                cell38.setCellValue(enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentAmount().doubleValue());
            } else {
                cell38.setCellValue(0);
            }

// 按需派送业务费用-票数
            Cell cell39 = dataRow.createCell(c++);
            cell39.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentNum() != null) {
                cell39.setCellValue(enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentNum());
            } else {
                cell39.setCellValue(0);
            }

// 按需派送业务费用-单价
            Cell cell40 = dataRow.createCell(c++);
            cell40.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentPrice() != null) {
                cell40.setCellValue(enterPaiGrossProfitSheet.getAsNeedDeliveryPaymentPrice().doubleValue());
            } else {
                cell40.setCellValue(0);
            }



            // 总派件数
            Cell cell41 = dataRow.createCell(c++);
            cell41.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getTotalDeliveryCount() != null) {
                cell41.setCellValue(enterPaiGrossProfitSheet.getTotalDeliveryCount());
            } else {
                cell41.setCellValue(0);
            }

// 补贴合计
            Cell cell42 = dataRow.createCell(c++);
            cell42.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getTotalSubsidyAmount() != null) {
                cell42.setCellValue(enterPaiGrossProfitSheet.getTotalSubsidyAmount().doubleValue());
            } else {
                cell42.setCellValue(0);
            }

// 单票补贴
            Cell cell43 = dataRow.createCell(c++);
            cell43.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPerParcelSubsidy() != null) {
                cell43.setCellValue(enterPaiGrossProfitSheet.getPerParcelSubsidy());
            } else {
                cell43.setCellValue(0);
            }

// 合计派费
            Cell cell44 = dataRow.createCell(c++);
            cell44.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getTotalDispatchFee() != null) {
                cell44.setCellValue(enterPaiGrossProfitSheet.getTotalDispatchFee().doubleValue());
            } else {
                cell44.setCellValue(0);
            }

// 单票派费
            Cell cell45 = dataRow.createCell(c++);
            cell45.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPerParcelDispatchFee() != null) {
                cell45.setCellValue(enterPaiGrossProfitSheet.getPerParcelDispatchFee());
            } else {
                cell45.setCellValue(0);
            }

// 航海扣款-金额
            Cell cell46 = dataRow.createCell(c++);
            cell46.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getMarineProjectPaymentAmount() != null) {
                cell46.setCellValue(enterPaiGrossProfitSheet.getMarineProjectPaymentAmount().doubleValue());
            } else {
                cell46.setCellValue(0);
            }

// 航海扣款-单票扣款
            Cell cell47 = dataRow.createCell(c++);
            cell47.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getMarineProjectPerParcelDeduction() != null) {
                cell47.setCellValue(enterPaiGrossProfitSheet.getMarineProjectPerParcelDeduction().doubleValue());
            } else {
                cell47.setCellValue(0);
            }

// 单票到手派费
            Cell cell48 = dataRow.createCell(c++);
            cell48.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getNetPerParcelIncome() != null) {
                cell48.setCellValue(enterPaiGrossProfitSheet.getNetPerParcelIncome().doubleValue());
            } else {
                cell48.setCellValue(0);
            }

// 派件收入
            Cell cell49 = dataRow.createCell(c++);
            cell49.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getDeliveryIncome() != null) {
                cell49.setCellValue(enterPaiGrossProfitSheet.getDeliveryIncome().doubleValue());
            } else {
                cell49.setCellValue(0);
            }

// 应付承包区金额部分
// 总派件数
            Cell cell50 = dataRow.createCell(c++);
            cell50.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getTotalPaiCount() != null) {
                cell50.setCellValue(enterPaiGrossProfitSheet.getTotalPaiCount());
            } else {
                cell50.setCellValue(0);
            }

// 基础派费
            Cell cell51 = dataRow.createCell(c++);
            cell51.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getBaseDispatchFee() != null) {
                cell51.setCellValue(enterPaiGrossProfitSheet.getBaseDispatchFee().doubleValue());
            } else {
                cell51.setCellValue(0);
            }

// 特价派费
            Cell cell52 = dataRow.createCell(c++);
            cell52.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getSpecialDiscountSubsidyFee() != null) {
                cell52.setCellValue(enterPaiGrossProfitSheet.getSpecialDiscountSubsidyFee().doubleValue());
            } else {
                cell52.setCellValue(0);
            }

// 补贴派费
            Cell cell53 = dataRow.createCell(c++);
            cell53.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getBonusDispatchFee() != null) {
                cell53.setCellValue(enterPaiGrossProfitSheet.getBonusDispatchFee().doubleValue());
            } else {
                cell53.setCellValue(0);
            }

// 考核派费
            Cell cell54 = dataRow.createCell(c++);
            cell54.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getAssessmentDispatchFee() != null) {
                cell54.setCellValue(enterPaiGrossProfitSheet.getAssessmentDispatchFee().doubleValue());
            } else {
                cell54.setCellValue(0);
            }

// 合计派费
            Cell cell55 = dataRow.createCell(c++);
            cell55.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getTotalDispatchAmount() != null) {
                cell55.setCellValue(enterPaiGrossProfitSheet.getTotalDispatchAmount().doubleValue());
            } else {
                cell55.setCellValue(0);
            }

// 单票派费
            Cell cell56 = dataRow.createCell(c++);
            cell56.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPerParcelDispatchAmount() != null) {
                cell56.setCellValue(enterPaiGrossProfitSheet.getPerParcelDispatchAmount().doubleValue());
            } else {
                cell56.setCellValue(0);
            }

// 航海通票扣款
            Cell cell57 = dataRow.createCell(c++);
            cell57.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getMarineGeneralPassTicketDeduction() != null) {
                cell57.setCellValue(enterPaiGrossProfitSheet.getMarineGeneralPassTicketDeduction().doubleValue());
            } else {
                cell57.setCellValue(0);
            }

// 航海单票扣款
            Cell cell58 = dataRow.createCell(c++);
            cell58.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getMarineSingleParcelDeduction() != null) {
                cell58.setCellValue(enterPaiGrossProfitSheet.getMarineSingleParcelDeduction().doubleValue());
            } else {
                cell58.setCellValue(0);
            }

// 政策互惠扣款
            Cell cell59 = dataRow.createCell(c++);
            cell59.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPolicyMutualBenefitDeduction() != null) {
                cell59.setCellValue(enterPaiGrossProfitSheet.getPolicyMutualBenefitDeduction().doubleValue());
            } else {
                cell59.setCellValue(0);
            }

// 政策互惠单票扣款
            Cell cell60 = dataRow.createCell(c++);
            cell60.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getPolicyMutualBenefitPerParcelDeduction() != null) {
                cell60.setCellValue(enterPaiGrossProfitSheet.getPolicyMutualBenefitPerParcelDeduction().doubleValue());
            } else {
                cell60.setCellValue(0);
            }

            // 星计划扣款
            Cell cell61 = dataRow.createCell(c++);
            cell61.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getStarPlanDeduction() != null) {
                cell61.setCellValue(enterPaiGrossProfitSheet.getStarPlanDeduction().doubleValue());
            } else {
                cell61.setCellValue(0);
            }

// 星计划单票扣款
            Cell cell62 = dataRow.createCell(c++);
            cell62.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getStarPlanPerParcelDeduction() != null) {
                cell62.setCellValue(enterPaiGrossProfitSheet.getStarPlanPerParcelDeduction().doubleValue());
            } else {
                cell62.setCellValue(0);
            }

// 实际付给承包区派费
            Cell cell63 = dataRow.createCell(c++);
            cell63.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getActualPaidDispatchFee() != null) {
                cell63.setCellValue(enterPaiGrossProfitSheet.getActualPaidDispatchFee().doubleValue());
            } else {
                cell63.setCellValue(0);
            }

// 单点派费调整
            Cell cell64 = dataRow.createCell(c++);
            cell64.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getSinglePointDispatchFeeAdjustment() != null) {
                cell64.setCellValue(enterPaiGrossProfitSheet.getSinglePointDispatchFeeAdjustment().doubleValue());
            } else {
                cell64.setCellValue(0);
            }

// 实际到手派费
            Cell cell65 = dataRow.createCell(c++);
            cell65.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getActualNetDispatchFee() != null) {
                cell65.setCellValue(enterPaiGrossProfitSheet.getActualNetDispatchFee().doubleValue());
            } else {
                cell65.setCellValue(0);
            }

// 进港派件毛利相关属性
// 单票结余派费
            Cell cell66 = dataRow.createCell(c++);
            cell66.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getRemainingDispatchFeePerParcel() != null) {
                cell66.setCellValue(enterPaiGrossProfitSheet.getRemainingDispatchFeePerParcel().doubleValue());
            } else {
                cell66.setCellValue(0);
            }

// 派费毛利率
            Cell cell67 = dataRow.createCell(c++);
            cell67.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getDispatchProfitMargin() != null) {
                cell67.setCellValue(enterPaiGrossProfitSheet.getDispatchProfitMargin().doubleValue());
            } else {
                cell67.setCellValue(0);
            }

// 派费毛利合计
            Cell cell68 = dataRow.createCell(c++);
            cell68.setCellStyle(borderStyle);
            if (enterPaiGrossProfitSheet.getTotalDispatchProfit() != null) {
                cell68.setCellValue(enterPaiGrossProfitSheet.getTotalDispatchProfit().doubleValue());
            } else {
                cell68.setCellValue(0);
            }
        }
        try {
            workbook.write(outputStream); // 将工作簿写入输出流
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            workbook.close(); // 关闭工作簿
        } catch (IOException e) {
            e.printStackTrace();
        }
        return collect;
    }

    @Override
    public List<HqNetworkBillDetail> point(ScEnterPaiGrossProfitSheetPointVo vo) {
        PageHelper.startPage(vo.getPageDate());
        return hqNetworkBillDetailMapper.scEnterPaiGrossProfitSheetPoint(vo);
    }

    @Override
    public List<ScPaiSet> selectAll() {
        return scPaiSetMapper.selectAll();
    }

    @Override
    public Boolean update(ScPaiSet scPaiSet) {
        return scPaiSetMapper.update(scPaiSet);
    }

    @Override
    public ScPaiSet findById(Integer id) {
        return scPaiSetMapper.findById(id);
    }

    @Override
    public R cache(DateStrVo dateStrVo) {
        Integer[] networkLevels = {0,1,2};
        List<String> days = GetDateStringUtils.getDateStr(dateStrVo.getStartDateStr(), dateStrVo.getEndDateStr());
        List<String> dateStrList = detailMapper.selectllDateStr();
        days.removeAll(dateStrList);
        for (String day : days) {
            String time = day;
            for (Integer networkLevel : networkLevels) {
                ScEnterPaiGrossProfitSheetVo vo = new ScEnterPaiGrossProfitSheetVo();
                vo.setStartTime(time);
                vo.setEndTime(time);
                vo.setNetworkLevel(networkLevel);
                List<ScEnterPaiGrossProfitSheet> scEnterPaiGrossProfitSheets = collectCache(vo);
                List<ScEnterPaiGrossProfitSheetDetail> scEnterPaiGrossProfitSheetDetails = new ArrayList<>();
                for (ScEnterPaiGrossProfitSheet scEnterPaiGrossProfitSheet : scEnterPaiGrossProfitSheets) {
                    ScEnterPaiGrossProfitSheetDetail scEnterPaiGrossProfitSheetDetail = new ScEnterPaiGrossProfitSheetDetail();
                    BeanUtils.copyProperties(scEnterPaiGrossProfitSheet,scEnterPaiGrossProfitSheetDetail);
                    scEnterPaiGrossProfitSheetDetail.setNetworkLevel(String.valueOf(networkLevel));
                    scEnterPaiGrossProfitSheetDetail.setCollectDate(time);
                    detailMapper.insert(scEnterPaiGrossProfitSheetDetail);
                    scEnterPaiGrossProfitSheetDetails.add(scEnterPaiGrossProfitSheetDetail);
                }
                //detailMapper.insertList(scEnterPaiGrossProfitSheetDetails);
            }
            System.out.println(time+"的数据缓存成功");
        }
        
        return R.ok("导入成功");
    }

    public List<TableVo> getTableVo(ScEnterPaiGrossProfitSheetVo vo) {
        List<TableVo> first = new ArrayList<>();
        TableVo firstTableVo = new TableVo();firstTableVo.setFields("collectDate");
        firstTableVo.setTranslate("统计日期");
        firstTableVo.setIsPoint(0);
        first.add(firstTableVo);
        firstTableVo = new TableVo();
        firstTableVo.setFields("name");
        firstTableVo.setTranslate("承包区名称");
        first.add(firstTableVo);
        firstTableVo = new TableVo();
        firstTableVo.setFields("actualHqAmount");
        firstTableVo.setTranslate("实收总部金额");
        first.add(firstTableVo);
        List<TableVo> second = new ArrayList<>();
        TableVo secondTableVo = new TableVo();
        secondTableVo.setFields("basePaiFee");
        secondTableVo.setTranslate("基础派费付费");
        List<TableVo> third = new ArrayList<>();
        String[] basePaiFee = {"basePaiFeeAmount", "basePaiFeeNum", "basePaiFeePrice"};

        InitTableVo initTableVo = new InitTableVo();
        initTableVo.setFields(basePaiFee);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("basePaiFeeNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(1);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);
        firstTableVo.setSunList(second);
//        first.add(firstTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("policyReciprocity");
        secondTableVo.setTranslate("政策互惠");
        third = new ArrayList<>();
        String[] policyReciprocity = {"policyReciprocityAmount", "policyReciprocityNum", "policyReciprocityPrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(policyReciprocity);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("policyReciprocityNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(2);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("wrongSign");
        secondTableVo.setTranslate("错签");
        third = new ArrayList<>();
        String[] wrongSign = {"wrongSignAmount", "wrongSignNum", "wrongSignPrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(wrongSign);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("wrongSignNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(3);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("repairSign");
        secondTableVo.setTranslate("补签");
        third = new ArrayList<>();
        String[] repairSign = {"repairSignAmount", "repairSignNum", "repairSignPrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(repairSign);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("repairSignNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(4);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("subsidyPaiFeePay");
        secondTableVo.setTranslate("补贴派费");
        third = new ArrayList<>();
        String[] subsidyPaiFeePay = {"subsidyPaiFeePayAmount", "subsidyPaiFeePayNum", "subsidyPaiFeePayPrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(subsidyPaiFeePay);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("subsidyPaiFeePayNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(5);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("entryOperate");
        secondTableVo.setTranslate("进港操作费");
        third = new ArrayList<>();
        String[] entryOperate = {"entryOperateFeeAmount", "entryOperateFeeNum", "entryOperateFeePrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(entryOperate);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("entryOperateFeeNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(6);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("specialPay");
        secondTableVo.setTranslate("特价业务付费");
        third = new ArrayList<>();
        String[] specialPay = {"specialPaymentAmount", "specialPaymentNum", "specialPaymentPrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(specialPay);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("specialPaymentNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(7);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("periodicPayment");
        secondTableVo.setTranslate("周期性派费付费");
        third = new ArrayList<>();
        String[] periodicPayment = {"periodicPaymentAmount", "periodicPaymentNum", "periodicPaymentPrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(periodicPayment);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("periodicPaymentNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(8);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("examinePaiFee");
        secondTableVo.setTranslate("考核派费");
        third = new ArrayList<>();
        String[] examinePaiFee = {"examinePaiFeeAmount", "examinePaiFeeNum", "examinePaiFeePrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(examinePaiFee);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("examinePaiFeeNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(9);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);
        
        
        secondTableVo = new TableVo();
        secondTableVo.setFields("starPlanPay");
        secondTableVo.setTranslate("星计划收费");
        third = new ArrayList<>();
        String[] starPlanPay = {"starPlanPayAmount", "starPlanPayNum", "starPlanPayPrice"};
        String substring = vo.getStartTime().substring(6);

        //当选择的日期为整月的日期条件时，才展示星计划收费的单价和票数
        int year = Integer.valueOf(vo.getStartTime().substring(0,4));
        int month = Integer.valueOf(vo.getStartTime().substring(4,6));
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        // 获取月份的第一天
        Calendar calendar = Calendar.getInstance();
        calendar.set(year, month - 1, 1);
        String firstDayOfMonth = sdf.format(calendar.getTime());
        // 获取月份的最后一天
        calendar.set(year, month, 1);
        calendar.add(Calendar.DATE, -1);
        String lastDayOfMonth = sdf.format(calendar.getTime());
        if (!firstDayOfMonth.equals(vo.getStartTime()) || !lastDayOfMonth.equals(vo.getEndTime())){
            starPlanPay = new String[]{"starPlanPayAmount"};
        }
        initTableVo = new InitTableVo();
        initTableVo.setFields(starPlanPay);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("starPlanPayNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(10);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("bulkPaiFeePayment");
        secondTableVo.setTranslate("大货派费付费");
        third = new ArrayList<>();
        String[] bulkPaiFeePayment = {"bulkPaiFeePaymentAmount", "bulkPaiFeePaymentNum", "bulkPaiFeePaymentPrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(bulkPaiFeePayment);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("bulkPaiFeePaymentNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(11);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("townshipSubsidyPayment");
        secondTableVo.setTranslate("乡镇村业务费用");
        third = new ArrayList<>();
        String[] townshipSubsidyPayment = {"townshipSubsidyPaymentAmount", "townshipSubsidyPaymentNum", "townshipSubsidyPaymentPrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(townshipSubsidyPayment);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("townshipSubsidyPaymentNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(12);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("asNeedDeliveryPayment");
        secondTableVo.setTranslate("按需派送业务费用");
        third = new ArrayList<>();
        String[] asNeedDeliveryPayment = {"asNeedDeliveryPaymentAmount", "asNeedDeliveryPaymentNum", "asNeedDeliveryPaymentPrice"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(asNeedDeliveryPayment);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("asNeedDeliveryPaymentNum".equals(tableVo.getFields())) {
                tableVo.setIsPoint(13);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("totalDeliveryCount");
        secondTableVo.setTranslate("总派件数");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("totalSubsidyAmount");
        secondTableVo.setTranslate("补贴合计");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("perParcelSubsidy");
        secondTableVo.setTranslate("单票补贴");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("totalDispatchFee");
        secondTableVo.setTranslate("合计派费");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("perParcelDispatchFee");
        secondTableVo.setTranslate("单票派费");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("marineProjectPayment");
        secondTableVo.setTranslate("航海扣款");
        third = new ArrayList<>();
        String[] marineProjectPayment = {"marineProjectPaymentAmount", "marineProjectPerParcelDeduction"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(marineProjectPayment);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        for (TableVo tableVo : third) {
            if ("marineProjectPaymentAmount".equals(tableVo.getFields())) {
                tableVo.setIsPoint(14);
                break; // 找到后立即退出循环
            }
        }
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("netPerParcelIncome");
        secondTableVo.setTranslate("单票到手派费");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("deliveryIncome");
        secondTableVo.setTranslate("派件收入");
        second.add(secondTableVo);




        firstTableVo = new TableVo();
        firstTableVo.setFields("shouldPay");
        firstTableVo.setTranslate("应付承包区金额");
        first.add(firstTableVo);
        second = new ArrayList<>();
        secondTableVo = new TableVo();
        secondTableVo.setFields("totalPaiCount");
        secondTableVo.setTranslate("总派件数");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("baseDispatchFee");
        secondTableVo.setTranslate("基础派费");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("specialDiscountSubsidyFee");
        secondTableVo.setTranslate("特价派费");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("bonusDispatchFee");
        secondTableVo.setTranslate("补贴派费");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("assessmentDispatchFee");
        secondTableVo.setTranslate("考核派费");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("totalDispatchAmount");
        secondTableVo.setTranslate("合计派费");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("perParcelDispatchAmount");
        secondTableVo.setTranslate("单票派费");
        second.add(secondTableVo);
        initTableVo = new InitTableVo();
        initTableVo.setCode("scEnterPai");
        firstTableVo.setSunList(second);
//        first.add(firstTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("marineGeneralPass");
        secondTableVo.setTranslate("航海通票扣款");
        third = new ArrayList<>();
        String[] marineGeneralPass = {"marineGeneralPassTicketDeduction", "marineSingleParcelDeduction"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(marineGeneralPass);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("policyMutualBenefit");
        secondTableVo.setTranslate("政策互惠扣款");
        third = new ArrayList<>();
        String[] policyMutualBenefit = {"policyMutualBenefitDeduction", "policyMutualBenefitPerParcelDeduction"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(policyMutualBenefit);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("starPlanDe");
        secondTableVo.setTranslate("星计划扣款");
        third = new ArrayList<>();
        String[] starPlanDe = {"starPlanDeduction", "starPlanPerParcelDeduction"};
        initTableVo = new InitTableVo();
        initTableVo.setFields(starPlanDe);
        initTableVo.setCode("scEnterPai");
        third = tableService.initTable(initTableVo);
        secondTableVo.setSunList(third);
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("actualPaidDispatchFee");
        secondTableVo.setTranslate("实际付给承包区派费");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("singlePointDispatchFeeAdjustment");
        secondTableVo.setTranslate("网点派费调整");
        second.add(secondTableVo);

        secondTableVo = new TableVo();
        secondTableVo.setFields("actualNetDispatchFee");
        secondTableVo.setTranslate("实际到手单票派费");
        second.add(secondTableVo);
//        initTableVo = new InitTableVo();
//        initTableVo.setCode("scEnterPai");
//        firstTableVo.setSunList(second);
//        second.add(secondTableVo);

        firstTableVo = new TableVo();
        firstTableVo.setFields("enter");
        firstTableVo.setTranslate("进港派件毛利");
        second = new ArrayList<>();
        secondTableVo = new TableVo();
        secondTableVo.setFields("remainingDispatchFeePerParcel");
        secondTableVo.setTranslate("单票结余派费");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("dispatchProfitMargin");
        secondTableVo.setTranslate("派费毛利率");
        second.add(secondTableVo);
        secondTableVo = new TableVo();
        secondTableVo.setFields("totalDispatchProfit");
        secondTableVo.setTranslate("派费毛利合计");
        second.add(secondTableVo);
//        initTableVo = new InitTableVo();
//        initTableVo.setCode("scEnterPai");
//        second.add(secondTableVo);
        firstTableVo.setSunList(second);
        first.add(firstTableVo);

        return first;
    }
}